package com.atguigu.url.controller;

import com.atguigu.url.service.DouYinVideoDownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version V1.0
 * @author: guangcheng
 * @date: 2021/11/16 12:54
 * @description:
 */
@RestController
public class DouYinVideoDown {

    @Autowired
    DouYinVideoDownService douYinVideoDownService;


    @GetMapping("/start/{tag}")
    public String getVideo(@PathVariable(value = "tag", required = true) Integer tag) {
        System.out.println(" 执行 ==> @GetMapping(\"/start/{tag}\") ");

        long start = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder("start0->");

        if (tag == 10010) {
            System.out.println("controller 10010");
            sb.append("start1->");
            //执行业务
            String res = douYinVideoDownService.executorDouYinVideoDown(tag);
            sb.append("res=" + res);
        }

        long end = System.currentTimeMillis();
        long dydTime = end - start;
        System.out.println("controller调用端用时 dydTime= " + dydTime + " 毫秒");

        return sb.toString();
    }


    @GetMapping("/statistics/download/alltime")
    public String downloadAllTime() {
        System.out.println(" 执行 ==> @GetMapping(\"/statistics/download/alltime\") ");

        long time = douYinVideoDownService.downloadAllTime();

        return "该批次url总计耗时: " + time + " 毫秒";
    }


    @GetMapping("/start/fast/{tag}")
    public String getVideoFast(@PathVariable(value = "tag", required = true) Integer tag) {
        System.out.println(" 执行 ==> @GetMapping(\"/start/fast/{tag}\") ");

        StringBuilder sb = new StringBuilder("start0->");

        if (tag == 10010) {
            System.out.println("controller 10010");
            sb.append("start1->");
            //执行业务
            String res = douYinVideoDownService.getDouYinVideoFast(tag);
            sb.append("res=" + res);
        }

        return sb.toString();
    }

}

